//
//  SearchViewFactory.m
//  住房条件帅选器
//
//  Created by MB__Lee on 2018/5/19.
//  Copyright © 2018年 MB__Lee. All rights reserved.
//

#import "SearchViewFactory.h"
// 搜索框----
#import "ResidenceSearchView.h" //住宅
#import "OffBuildingSearchView.h" //写字楼
#import "ShopSearchView.h"// 商铺

#import "MapResidenceSearchView.h"
#import "MapOffBuilSearchView.h"
#import "MapShopSearchView.h"


@implementation SearchViewFactory

+(BaseSearchView *)creatSearViewWithFrame:(CGRect)frame searViewType:(SearViewType)searViewType{
    BaseSearchView *baseSearchview;
    
    if (searViewType == SearViewTypeResidence) { //住宅
        baseSearchview  = [self SearchViewAddOtherView_residenceFrame:frame];
    }else if (searViewType == SearViewTypeOffBuiling){ //写字楼
        baseSearchview = [self SearchViewAddOtherView_offBuildingFrame:frame];
    }else if (searViewType == SearViewTypeShop){  // 商铺
        baseSearchview  = [self SearchViewAddOtherView_shopFrame:frame];
    }else if(searViewType == SearViewTypeMapResidence){ // 地图找房--住宅
        baseSearchview = [self SearchViewAtMapView_residentFrame:frame];
    }else if (searViewType  == SearViewTypeMapOffBuilding){// 地图找房--写字楼
        baseSearchview = [self SearchViewAtMapView_offBuildingFrame:frame];
    }else if (searViewType == SearViewTypeMapShop){// 地图找房--商铺
        baseSearchview = [self SearchViewAtMapView_shopFrame:frame];
    }


    return  baseSearchview;
    
}
#pragma mark --筛选框--住宅---普通

+(BaseSearchView *)SearchViewAddOtherView_residenceFrame:(CGRect)frame{
    CGFloat searchHeight = frame.size.height; //搜索框的高度
   BaseSearchView *baseSearchview =  [[ResidenceSearchView alloc] initWithFrame:frame btnMut:@[@"区域",@"租金",@"户型",@"更多"]];
   
    
    
    //区域
    AreaTableview *are = [[AreaTableview alloc] initWithFrame:CGRectMake(0, searchHeight, baseSearchview.bounds.size.width, SCREEN_HIGHT * 0.8)];
    
    //租金
    PriceTableview *rent =  [[PriceTableview alloc] initWithFrame:CGRectMake(0, searchHeight, baseSearchview.bounds.size.width, MBScale(300))]; //他的高度会更多数据多少来计算
     rent.priceType = PriceTableviewTypeResidence;
    
    //户型
    BaseTypeTableVeiw *roomtype = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeBottomBTN withFrame:CGRectMake(0, searchHeight, SCREEN_WIDTH, 300)];
    // 弄个空用来显示底部 自定义的 填写框
    roomtype.sourceMut = @[@"全部",@"一室",@"二室",@"三室",@"四室",@"四室以上",@" "];
    //更多
    MBBTNTableview *more = [MBBTNTableviewFactory MBBTNTableviewFactoryCreatWithType:HouseTypeResidence withFrame:CGRectMake(0, searchHeight, baseSearchview.bounds.size.width, 0.7*SCREEN_HIGHT)];
    
    
    are.delegate = baseSearchview;
    rent.ptDelegate = baseSearchview;
    roomtype.BaseDelegate = baseSearchview;
    more.BTNDelegate = baseSearchview;
    baseSearchview.viewArray = @[are,rent,roomtype,more];
    
    
    return baseSearchview;
}
#pragma mark --筛选框--写字楼---普通
+(BaseSearchView *)SearchViewAddOtherView_offBuildingFrame:(CGRect)frame{
    CGFloat searchHeight = frame.size.height; //搜索框的高度
    BaseSearchView *baseSearchview =  [[OffBuildingSearchView alloc] initWithFrame:frame btnMut:@[@"区域",@"租金",@"面积",@"特色"]];
    
    
    
    //区域  ---写字楼
    AreaTableview *are = [[AreaTableview alloc] initWithFrame:CGRectMake(0, searchHeight, baseSearchview.bounds.size.width, SCREEN_HIGHT * 0.8)];
    
    //租金 ---写字楼
    PriceTableview *rent =  [[PriceTableview alloc] initWithFrame:CGRectMake(0, searchHeight, baseSearchview.bounds.size.width, MBScale(200))]; //他的高度会更多数据多少来计算
    rent.priceType = PriceTableviewTypeOffBuilding;
    
    // 面积 ---写字楼
    BaseTypeTableVeiw *square = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeModel withFrame:CGRectMake(0, searchHeight, baseSearchview.bounds.size.width,300)];
    square.sourceMut = [self offBuildingSquareSource];
    
    //特色
    BaseTypeTableVeiw *character = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeBase withFrame:CGRectMake(0, searchHeight, baseSearchview.bounds.size.width, 300)];
    NSArray *characterSource  = @[@"不限",@"标志性建筑",@"5A甲级",@"名企入驻",@"地铁口附近",@"电梯口",@"商业街附近",@"整层整栋",@"小面积",@"停车位多",@"可注册公司"];
    character.sourceMut = [NSMutableArray arrayWithArray:characterSource];
    
    are.delegate = baseSearchview;
    rent.ptDelegate = baseSearchview;
    square.BaseDelegate = baseSearchview;
    character.BaseDelegate = baseSearchview;
    
    baseSearchview.viewArray = @[are,rent,square,character];
    
    return baseSearchview;
    
    
}
#pragma mark --筛选框--商铺---普通
+(BaseSearchView *)SearchViewAddOtherView_shopFrame:(CGRect)frame{
    CGFloat searchHeight = frame.size.height; //搜索框的高度
    CGFloat searchWidth = frame.size.width; //搜索框的高度
    BaseSearchView *baseSearchview =  [[ResidenceSearchView alloc] initWithFrame:frame btnMut:@[@"区域",@"租金",@"面积",@"特色"]];
    
    //区域
    AreaTableview *are = [[AreaTableview alloc] initWithFrame:CGRectMake(0, searchHeight, searchWidth, SCREEN_HIGHT * 0.8)];
    
    //租金
    PriceTableview *rent =  [[PriceTableview alloc] initWithFrame:CGRectMake(0, searchHeight, searchWidth, MBScale(200))]; //他的高度会更多数据多少来计算
    rent.priceType = PriceTableviewTypeShop;
    
    
    
    
    // 面积
    BaseTypeTableVeiw *square = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeModel withFrame:CGRectMake(0, searchHeight, searchWidth,300)];
    square.sourceMut = [self shopSquareSource];
    [square setMinPlaceHolder:@"最小面积" max:@"最大面积"];
    
    
    //特色
    BaseTypeTableVeiw *character = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeBase withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    NSArray *characterSource  = @[@"不限",@"沿街旺铺",@"繁华地段",@"专业市场",@"住宅底商",@"综合体配套",@"地铁口附近",@"小面积",@"独栋整层",@"知名商户入驻",@"可分隔办公室"];
    character.sourceMut = [NSMutableArray arrayWithArray:characterSource];
    
    are.delegate = baseSearchview;
    rent.ptDelegate = baseSearchview;
    square.BaseDelegate = baseSearchview;
    character.BaseDelegate = baseSearchview;
    
    baseSearchview.viewArray = @[are,rent,square,character];
    return baseSearchview;
}


#pragma mark --筛选框--住宅---地图
+(BaseSearchView *)SearchViewAtMapView_residentFrame:(CGRect)frame{
    CGFloat searchHeight = frame.size.height; //搜索框的高度
    CGFloat searchWidth = frame.size.width; //搜索框的高度
    BaseSearchView *baseSearchview =  [[MapResidenceSearchView alloc] initWithFrame:frame btnMut:@[@"租金",@"面积",@"户型",@"特色"]];
//     住宅租金
    BaseTypeTableVeiw *mapRent  = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeMapModelRent withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    mapRent.sourceMut = [self residenceRentSource];
    mapRent.baseType =BaseTypeMapModelRent;
    //住宅面积
    BaseTypeTableVeiw *mapSquare = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeMapModelSquare withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    mapSquare.sourceMut = [self residenceSquareSource];
    mapSquare.baseType = BaseTypeMapModelSquare;
    //住宅户型
    BaseTypeTableVeiw *roomtype = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeMapBaseCategory withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    NSMutableArray *cateMut = [NSMutableArray arrayWithObjects:@"全部",@"一室",@"二室",@"三室",@"四室",@"四室以上",nil];
    roomtype.sourceMut = cateMut;
    roomtype.baseType = BaseTypeMapBaseCategory;
    
    // 住宅特色
    BaseTypeTableVeiw *chacter  = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeMapBaseCharater withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    chacter.sourceMut = [NSMutableArray arrayWithArray:@[@"不限",@"拎包入住",@"首次出租",@"采光好",@"停车位多",@"地铁口附近",@"商业街附近",@"学校附近",@"有电梯",@"有阳台",@"有花园",@"有阁楼",@"有地下室"]];
    chacter.baseType = BaseTypeMapBaseCharater;
    
    mapRent.BaseDelegate = baseSearchview;
    mapSquare.BaseDelegate = baseSearchview;
    roomtype.BaseDelegate = baseSearchview;
    chacter.BaseDelegate = baseSearchview;
    
    baseSearchview.viewArray = @[mapRent,mapSquare,roomtype,chacter];
    return baseSearchview;
}
#pragma mark -写字楼--
+(BaseSearchView *)SearchViewAtMapView_offBuildingFrame:(CGRect)frame{
    CGFloat searchHeight = frame.size.height; //搜索框的高度
    CGFloat searchWidth = frame.size.width; //搜索框的高度
    BaseSearchView *baseSearchview =  [[MapResidenceSearchView alloc] initWithFrame:frame btnMut:@[@"租金",@"面积",@"类型",@"特色"]];
    // 写字楼租金
    BaseTypeTableVeiw *mapRent  = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeMapModelRent withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    mapRent.sourceMut = [self offBuildingRentSource];
    mapRent.baseType =BaseTypeMapModelRent;
    //写字楼面积
    BaseTypeTableVeiw *mapSquare = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeMapModelSquare withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    mapSquare.sourceMut = [self offBuildingSquareSource];
    mapSquare.baseType = BaseTypeMapModelSquare;
    //写字楼类型
    BaseTypeTableVeiw *cate = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeMapBaseNormal withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    NSMutableArray *cateMut = [NSMutableArray arrayWithObjects:@"不限",@"纯写字楼",@"商业综合体",@"商住连用楼",@"其他",nil];
    cate.sourceMut = cateMut;
    cate.baseType = BaseTypeMapBaseNormal;
    
    // 写字楼特色
    BaseTypeTableVeiw *chacter  = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeMapBaseCharater withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    chacter.sourceMut = [NSMutableArray arrayWithArray:@[@"不限",@"标志性建筑", @"5A甲级", @"名企入驻", @"地铁口附近", @"电梯口", @"商业街附近", @"整层整栋", @"小面积", @"停车位多", @"可注册公司"]];
    chacter.baseType = BaseTypeMapBaseCharater;
    
    mapRent.BaseDelegate = baseSearchview;
    mapSquare.BaseDelegate = baseSearchview;
    cate.BaseDelegate = baseSearchview;
    chacter.BaseDelegate = baseSearchview;
    
    baseSearchview.viewArray =  @[mapRent,mapSquare,cate,chacter];
    return baseSearchview;
}
#pragma mark -商铺--
+(BaseSearchView *)SearchViewAtMapView_shopFrame:(CGRect)frame{
    CGFloat searchHeight = frame.size.height; //搜索框的高度
    CGFloat searchWidth = frame.size.width; //搜索框的高度
    BaseSearchView *baseSearchview =  [[MapResidenceSearchView alloc] initWithFrame:frame btnMut:@[@"租金",@"面积",@"类型",@"特色"]];
    // 写字楼租金
    BaseTypeTableVeiw *mapRent  = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeMapModelRent withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    mapRent.sourceMut = [self shopRentSource];
    mapRent.baseType = BaseTypeMapModelRent;
    //写字楼面积
    BaseTypeTableVeiw *mapSquare = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeMapModelSquare withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    mapSquare.sourceMut = [self shopSquareSource];
    mapSquare.baseType = BaseTypeMapModelSquare;
    //写字楼类型
    BaseTypeTableVeiw *cate = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeMapBaseNormal withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    NSMutableArray *cateMut = [NSMutableArray arrayWithObjects:@"不限",@"购物中心",@"社区商业",@"综合体配套",@"其他",nil];
    cate.sourceMut = cateMut;
    cate.baseType = BaseTypeMapBaseNormal;
    
    // 写字楼特色
    BaseTypeTableVeiw *chacter  = [MutiBaseFactory creatTableviewWithBaseType:BaseTypeMapBaseCharater withFrame:CGRectMake(0, searchHeight, searchWidth, 300)];
    chacter.sourceMut = [NSMutableArray arrayWithArray:@[@"不限",@"沿街旺铺", @"繁华地段", @"专业市场", @"住宅底商", @"综合体配套", @"地铁口附近", @"小面积", @"独栋整层", @"知名商户入驻", @"可分隔办公室"]];
    chacter.baseType = BaseTypeMapBaseCharater;
    
    mapRent.BaseDelegate = baseSearchview;
    mapSquare.BaseDelegate = baseSearchview;
    cate.BaseDelegate = baseSearchview;
    chacter.BaseDelegate = baseSearchview;
    
//    baseSearchview.viewArray =  @[mapRent,mapSquare,cate,chacter];
    
    baseSearchview.viewArray = @[mapRent,mapSquare,cate,chacter];
    return baseSearchview;
}

#pragma mark --写字楼面积---地图找房
+(NSMutableArray *)offBuildingSquareSource{
  
    NSMutableArray *offBuildingMut = [NSMutableArray array];
    
    // 不限
    BaseModel *noModel = [[BaseModel alloc] init];
    noModel.name = @"不限";
    [offBuildingMut addObject:noModel];
    
    // 80平方米
    BaseModel *EightyModel = [[BaseModel alloc] init];
    EightyModel.name = @"80㎡以下";
    EightyModel.value_end = @"80";
    [offBuildingMut addObject:EightyModel];
    
    //通过数据 得到 面积模型
    NSArray *source  = @[@"80-120",@"120-150",@"150-200",@"200-300",@"300-400",@"400-500",@"500-800",@"800-1200",@"1200-2000"];
    [offBuildingMut addObjectsFromArray:[self getModelArrayWithArray:source]];
    
    
    BaseModel *lastModel = [[BaseModel alloc] init];
    lastModel.name = @"2000㎡以上";
    lastModel.value_start = @"2000";
    
    [offBuildingMut addObject:lastModel];
    
//
//    //占位模型
//    BaseModel *placeModel =[[BaseModel alloc] init];
//    [offBuildingMut addObject:placeModel];
    
    return  offBuildingMut;
}
#pragma mark ---商铺面积--地图找房
+(NSMutableArray *)shopSquareSource{
    NSMutableArray *shopMut = [NSMutableArray array];
    
    // 不限
    BaseModel *noModel = [[BaseModel alloc] init];
    noModel.name = @"不限";
    [shopMut addObject:noModel];
    
    // 20平方米
    BaseModel *EightyModel = [[BaseModel alloc] init];
    EightyModel.name = @"20㎡以下";
    EightyModel.value_end = @"20";
    [shopMut addObject:EightyModel];
    
    //通过数据 得到 面积模型
    NSArray *source  = @[@"20-50",@"50-80",@"80-120",@"120-200",@"200-500"];
    [shopMut addObjectsFromArray:[self getModelArrayWithArray:source]];
    
    BaseModel *lastModel = [[BaseModel alloc] init];
    lastModel.name = @"500㎡以上";
    lastModel.value_start = @"500";
    [shopMut addObject:lastModel];
    
//    //占位模型
//    BaseModel *placeModel =[[BaseModel alloc] init];
//    [shopMut addObject:placeModel];
    
    return shopMut;
    
}
#pragma mark --住宅面积 ---地图找房
+(NSMutableArray *)residenceSquareSource{
    NSMutableArray *squareMut = [NSMutableArray array];
    
    // 不限
    BaseModel *noModel = [[BaseModel alloc] init];
    noModel.name = @"不限";
    [squareMut addObject:noModel];
    
    // 20平方米
    BaseModel *EightyModel = [[BaseModel alloc] init];
    EightyModel.name = @"20㎡以下";
    EightyModel.value_end = @"20";
    [squareMut addObject:EightyModel];
    
    //通过数据 得到 面积模型
    NSArray *source  = @[@"20-40",@"40-60",@"60-80",@"80-100",@"100-120",@"120-150",@"150-200"];
    [squareMut addObjectsFromArray:[self getModelArrayWithArray:source]];
    
    BaseModel *lastModel = [[BaseModel alloc] init];
    lastModel.name = @"200㎡以上";
    lastModel.value_start = @"200";
    [squareMut addObject:lastModel];
    
//    //占位模型
//    BaseModel *placeModel =[[BaseModel alloc] init];
//    [squareMut addObject:placeModel];
    
    return squareMut;
}
//通过字符串得到 面积模型
+(NSMutableArray *)getModelArrayWithArray:(NSArray *)source{
    
    NSMutableArray *mut =  [NSMutableArray array];
    
    for (NSString *name in source) {
        NSArray *twoIndex = [name componentsSeparatedByString:@"-"];
        BaseModel *model = [[BaseModel alloc] init];
        NSString *realName = [name stringByAppendingString:@"㎡"];
        
        model.name = realName;
        model.value_start = twoIndex[0];
        model.value_end = twoIndex[1];
        
        [mut addObject:model];
    }
    return  mut;
}
#pragma mark --住宅租金--
+(NSMutableArray *)residenceRentSource{
    NSMutableArray *squareMut = [NSMutableArray array];
    
    // 不限
    BaseModel *noModel = [[BaseModel alloc] init];
    noModel.name = @"不限";
    [squareMut addObject:noModel];
    
    // 1000元一下
    BaseModel *EightyModel = [[BaseModel alloc] init];
    EightyModel.name = @"1000以下";
    EightyModel.value_end = @"1000";
    [squareMut addObject:EightyModel];
    
    //通过数据 得到 面积模型
    NSArray *source  = @[@"1000-2000",@"2000-3000",@"3000-4000",@"4000-5000",@"5000-6000",@"6000-7000",@"7000-8000",@"8000-9000",@"9000-10000"];
    [squareMut addObjectsFromArray:[self getRentModelArrayWithArray:source withSting:@"元"]];
    
    BaseModel *lastModel = [[BaseModel alloc] init];
    lastModel.name = @"10000元以上";
    lastModel.value_start = @"10000";
    [squareMut addObject:lastModel];
    
  
    
    return squareMut;
}
#pragma mark --写字楼租金
+(NSMutableArray *)offBuildingRentSource{
    NSMutableArray *offBuiding = [NSMutableArray array];
    
    // 不限
    BaseModel *noModel = [[BaseModel alloc] init];
    noModel.name = @"不限";
    [offBuiding addObject:noModel];
    
    // 1000元一下
    BaseModel *EightyModel = [[BaseModel alloc] init];
    EightyModel.name = @"40元/㎡以下";
    EightyModel.value_end = @"40";
    [offBuiding addObject:EightyModel];
    
    //通过数据 得到 面积模型
    NSArray *source  = @[@"40-60",@"60-80",@"80-100",@"100-120",@"120-140"];
    [offBuiding addObjectsFromArray:[self getRentModelArrayWithArray:source withSting:@"元/㎡.月"]];
    
    BaseModel *lastModel = [[BaseModel alloc] init];
    lastModel.name = @"140元/㎡.月以上";
    lastModel.value_start = @"140";
    [offBuiding addObject:lastModel];
    
//    //占位模型
//    BaseModel *placeModel =[[BaseModel alloc] init];
//    [offBuiding addObject:placeModel];
    
    return offBuiding;
}
#pragma mark --商铺租金
+(NSMutableArray *)shopRentSource{
    NSMutableArray *shopMut = [NSMutableArray array];
    
    // 不限
    BaseModel *noModel = [[BaseModel alloc] init];
    noModel.name = @"不限";
    [shopMut addObject:noModel];
    
    // 1000元一下
    BaseModel *EightyModel = [[BaseModel alloc] init];
    EightyModel.name = @"2000元以下";
    EightyModel.value_end = @"2000";
    [shopMut addObject:EightyModel];
    
    //通过数据 得到 面积模型
    NSArray *source  = @[@"2000-5000",@"5000-8000",@"8000-10000",@"10000-20000",@"20000-50000"];
    [shopMut addObjectsFromArray:[self getRentModelArrayWithArray:source withSting:@"元/月"]];
    
    BaseModel *lastModel = [[BaseModel alloc] init];
    lastModel.name = @"50000元以上";
    lastModel.value_start = @"50000";
    [shopMut addObject:lastModel];
    
//    //占位模型
//    BaseModel *placeModel =[[BaseModel alloc] init];
//    [shopMut addObject:placeModel];
    
    return shopMut;
}
#pragma mark ---通过字符串得到价格区间模型
+(NSMutableArray *)getRentModelArrayWithArray:(NSArray *)source withSting:(NSString *)name{
    
    NSMutableArray *mut =  [NSMutableArray array];
    
    for (NSString *price in source) {
        NSArray *twoIndex = [price componentsSeparatedByString:@"-"];
        BaseModel *model = [[BaseModel alloc] init];
        NSString *realName = [price stringByAppendingString:name];
        
        model.name = realName;
        model.value_start = twoIndex[0];
        model.value_end = twoIndex[1];
        
        [mut addObject:model];
    }
    return  mut;
}


@end
